//手机号显示*号方法
function phone(tel) {
	// var tel = 18810399133;
	// tel = "" + tel;
	var tell = tel.replace(tel.substring(3, 7), "****");
	return tell
}


// 轻提示封装
function Toast(text) {
	uni.showToast({
		title: text,
		icon: 'none'
	})
}

//数字小数精准度丢失问题处理 四舍五入法
function Exact(number) {
	let num = parseFloat((number).toPrecision(12))
	return num
}

// 金额格式化方法
/**
 * 将数值四舍五入(保留2位小数)后格式化成金额形式
 *
 * @param num 数值(Number或者String)
 * @return 金额格式的字符串,如'1,234,567.45'
 * @type String
 */
function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g, '');
	if (isNaN(num))
		num = "0";
	var sign = (num == (num = Math.abs(num)));
	num = Math.floor(num * 100 + 0.50000000001);
	var cents = num % 100;
	num = Math.floor(num / 100).toString();
	if (cents < 10)
		cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
		num = num.substring(0, num.length - (4 * i + 3)) + ',' +
		num.substring(num.length - (4 * i + 3));
	return (((sign) ? '' : '-') + num + '.' + cents);
}

// 后端数据不规范处理 处理 空 null undefine
function jsonText(text) {
	if (!text) {
		text = text
	} else {
		text = ''
	}
	return text
}



function isAllEqual(array) {
		if (array.length > 0) {
			return !array.some(function(value, index) {
				return value !== array[0];
			});
		} else {
			return true;
		}
	}


	module.exports = {
		Toast: Toast,
		phone: phone,
		formatCurrency: formatCurrency,
		Exact: Exact,
		jsonText: jsonText,
		isAllEqual:isAllEqual
	}
